package com.hk.service.impl;

import com.github.pagehelper.PageHelper;
import com.hk.mapper.IOnlineMessageMapper;
import com.hk.model.OnlineMessage;
import com.hk.service.IOnlineMessageService;
import com.hk.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @Author: zhe
 * @Date: 2021/6/21 16:21
 * @Statement: 在线留言Service层接口实现类
 */
@Service
public class OnlineMessageServiceImpl implements IOnlineMessageService {

    @Autowired
    IOnlineMessageMapper iOnlineMessageMapper;

    @Override
    public List<OnlineMessage> findAll(Integer page, Integer limit, OnlineMessage t) {
        PageHelper.startPage(page,limit);
        List<OnlineMessage> onlineMessageList = iOnlineMessageMapper.findAll(t);
        return onlineMessageList;
    }

    @Override
    public int count(Integer page, Integer limit, OnlineMessage t) {
//        PageHelper.startPage(page,limit);
        int count = iOnlineMessageMapper.count(t);
        return count;
    }

    @Override
    public OnlineMessage findById(Integer id) {
        OnlineMessage onlineMessage = iOnlineMessageMapper.findById(id);
        return onlineMessage;
    }

    @Override
    public int save(OnlineMessage t) {
        String dateTimeString = DateUtils.dateTimeString(new Date());
        t.setGmtCreate(dateTimeString);
        t.setGmtModified(dateTimeString);
        int save = iOnlineMessageMapper.save(t);
        if (save == 1) {
            System.out.println("留言信息添加成功！");
        }
        return save;
    }

    @Override
    public int update(OnlineMessage t) {
        String dateTimeString = DateUtils.dateTimeString(new Date());
        t.setGmtModified(dateTimeString);
        int update = iOnlineMessageMapper.update(t);
        if (update == 1) {
            System.out.println("留言信息修改成功！");
        }
        return update;
    }

    @Override
    public int delete(Integer id) {
        int delete = iOnlineMessageMapper.delete(id);
        if (delete == 1) {
            System.out.println("留言信息删除成功！");
        }
        return delete;
    }

}
